#!/usr/bin/python
# -*- coding: utf-8 -*-
import os
import sys
import time

import re

from engine.common import *
if sys.platform == "darwin":
    adbpath = "adb "
else:
    adbpath = "/usr/bin/adb "
if (sys.argv.__len__())<4:
    print( "参数个数少了")
    exit(0)
handset = sys.argv[1]
currentHandsetSnumber = sys.argv[2]
command = sys.argv[3]
resultF = sys.argv[4]

filePath = sys.argv[5]

def getAddress(content):

    pattern = r',|\.|/|;|\'|`|\[|\]|<|>|\?|:|"|\{|\}|\~|!|@|#|\$|%|\^|&|\(|\)|-|=|\_|\+|，|。|、|；|‘|’|【|】|·|！| |…|（|）'
    test_text = 'b,b.b/b;b\'b`b[b]b<b>b?b:b"b{b}b~b!b@b#b$b%b^b&b(b)b-b=b_b+b，b。b、b；b‘b’b【b】b·b！b b…b（b）b'
    result_list = re.split(pattern, content)
    print(result_list)
    if result_list.__len__()>5:
        return result_list[2]+result_list[4]
    else:
        return "error"
def descSave( handset,currentHandsetSnumber,resultF,filePath="./temp/result.txt",delay=5 ):
    ret = False
    print(handset)
    print(currentHandsetSnumber)
    setHandsetType(handset)
    setHandsetSno(currentHandsetSnumber)
    content = getAndSetMsgFromHandsetCliper("test",currentHandsetSnumber)

    if not os.path.exists(getHandsetFileSavePath(resultF)):
        os.mkdir(getHandsetFileSavePath(resultF))



    with open(getHandsetFileSavePath(resultF + getAddress(content)+".txt"),'w') as f:
        print('wriete to file'+content)
        f.write(content)





    with open(getHandsetFileSavePath(filePath),'w')as f:
        if ret == True:
            f.write('True')
            return True  #TRUE 状态转移
        else:
            f.write('False')
            return False



if command =="descSave".strip():
    descSave(handset,currentHandsetSnumber,resultF,filePath)
